package com.example.littlexs.rxjavademo;

import android.os.Bundle;
import android.util.Log;
import android.widget.Button;
import android.widget.TextView;

import com.example.littlexs.rxjavademo.entity.HttpExceptionEntity;
import com.example.littlexs.rxjavademo.entity.MovieEntity;
import com.example.littlexs.rxjavademo.http.SimpleMyCallBack;
import com.example.littlexs.rxjavademo.model.MovieResultDO;

import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;
import rx.Subscriber;
import rx.Subscription;
import rx.functions.Action1;

public class MainActivity extends BaseActivity {

    @InjectView(R.id.btn_getData)
    Button btnGetData;
    @InjectView(R.id.tv_showData)
    TextView tvShowData;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.inject(this);
        initApi();
    }

    @OnClick(R.id.btn_getData)
    void btnGetData(){
        getData();
    }

    public void getData(){
        Subscription subscription = myMethods.getTopMovie(0,10)
                .subscribe(newMySubscriber(new SimpleMyCallBack<MovieResultDO<List<MovieEntity>>>() {
                    @Override
                    public void onNext(MovieResultDO<List<MovieEntity>> movieEntities) {
                        Log.i("---","---onNext---");
                        List<MovieEntity> list = movieEntities.getSubjects();
                        tvShowData.setText(list.size()+movieEntities.getTitle());
                    }
                    @Override
                    public void onError(HttpExceptionEntity httpExceptionEntity) {
                        super.onError(httpExceptionEntity);
                        Log.i("---","---onError---");
                    }
                }));
    }
}
